package com.ttai.presenter.activity;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.ttai.model.dao.DBHelper;
import com.ttai.model.net.AcountUse;
import com.ttai.model.net.ResponseInfo;
import com.ttai.presenter.base.BasePresenter;
import com.ttai.ui.activity.AcountItem;
import com.ttai.ui.activity.EnterPage;
import com.ttai.ui.activity.Register;
import com.ttai.untils.AesAndroid;
import com.ttai.untils.Constant;

import retrofit2.Call;

public class AcountItemPresenter extends BasePresenter{
    AcountItem acountItem;
    private String phonenumber;
    private String value;
    private String xorAcount;
    private String xorPassword;

    public String getXorAcount() {
        return xorAcount;
    }

    public String getXorPassword() {
        return xorPassword;
    }

//    public String getValue() {
//        return value;
//    }
    public AcountItemPresenter(AcountItem acountItem) {
        this.acountItem = acountItem;
    }

    @Override
    protected void showError(String message) {

    }

    @Override
    protected void parseJson(JsonObject json) {
        Gson gson = new Gson();
        AcountUse acountUse = gson.fromJson(json,AcountUse.class);
        String acount = acountUse.getAccount();
        String password = acountUse.getPassWord();
        xorAcount = AesAndroid.decrypt(acountItem.secretKey,Constant.unicode2String(acount));
        xorPassword = AesAndroid.decrypt(acountItem.secretKey, Constant.unicode2String(password));

        acountItem.setText();

    }

    public void deCode(String token,String accountName){
        Call<ResponseInfo> deCodeInfo = responseInfoApi.getAcountUser(token,accountName);
        deCodeInfo.enqueue(new CallBackAdapter());
    }

//    public void dealDB() {
//        if (HomePresrenter.myPhone==null || HomePresrenter.myPhone.isEmpty()){
//            if(Register.phonenumber==null || Register.phonenumber.isEmpty()){
//                phonenumber = EnterPage.enterphonenumber;
//            }else{
//                phonenumber =Register.phonenumber;
//            }
//        }else {
//            phonenumber =HomePresrenter.myPhone;
//        }
//
//        DBHelper dbHelper = DBHelper.getInstance(acountItem);
//        SQLiteDatabase sqLiteDatabase=dbHelper.getWritableDatabase();
//        Cursor cursor=sqLiteDatabase.query("tipacount", new String[]{"tip"}, "phone= '"+phonenumber+"'", null,null, null, null);
//        while (cursor.moveToNext()){
//            value=cursor.getString(0);
//        }
//        cursor.close();
//    }
}
